﻿using System;
using System.Threading;
using System.Web.UI;

using Sunyi.Project.WebPoint.BusinessLogic;
using Sunyi.Project.WebPoint.DataContract;
using Sunyi.Project.WebPoint.WebControl;

namespace ActivitySystem.Web
{
    public static class ExceptionHandler
    {
        public static void Handle(Control control, Exception ex)
        {
            Handle(control.GetType().Name, ex);

            WebControlCommon.ShowClientMessage(control, ex.Message);
        }

        public static void Handle(string source, Exception ex)
        {
            Log log = new Log { Level = LogLevel.Error.ToString(), Source = source };
            log.UserName = Thread.CurrentThread.Name;
            log.Data = ex.ToString();

            Logger.Write(log);
        }
    }
}